/*                                                                      
 Copyright 2018 hzheng@gzhu.edu.cn              
                                                                         
 Licensed under the Apache License, Version 2.0 (the "License");         
 you may not use this file except in compliance with the License.        
 You may obtain a copy of the License at                                 
                                                                         
     http://www.apache.org/licenses/LICENSE-2.0                          
                                                                         
  Unless required by applicable law or agreed to in writing, software    
 distributed under the License is distributed on an "AS IS" BASIS,       
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and     
 limitations under the License.                                          
 */                                                                      
/*+***********************************************************
Filename: zh_pc_v02.v
Description: a module that generate program counter value.
       support pc=pc+1 and pc=pc+offset
Modification:
  2018.07.27 createion by Zheng Hui

************************************************************-*/

module zh_pc_v02(
  input core_clk,
  input rst_n,
  input [31:0] pc_offset,
  input jump_flag,
  output [31:0] pc_value
);

  wire [31:0] pc_r;
  wire [31:0] pc_next;

  wire [31:0] pc_next_1;
  assign pc_next_1 = pc_r+1;
  wire [31:0] pc_offset_1;
  assign pc_offset_1 = {pc_offset[31], pc_offset[31:1]};

  assign pc_next=jump_flag?(pc_next_1+pc_offset_1):pc_next_1;

  sirv_gnrl_dfflr #(32) pc_dfflr (1'b1, pc_next, pc_r, core_clk, rst_n);

  assign pc_value = pc_r;

endmodule


